//
// Decompiled by Jadx - 498ms
//
package ed;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import androidx.activity.b;
import d.f;
import dq.a;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import okhttp3.v;

public final class d {
    public static final String a;
    public static final String b;
    public static final String c;
    public static final String d;
    public static final String e;
    public static final String f;

    static {
        String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        a = absolutePath;
        StringBuilder k = b.k(absolutePath);
        k.append(File.separator);
        String sb = k.toString();
        b = sb;
        c = b.x(sb, "Android");
        d = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
        e = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();
        f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
    }

    public static void g(Object obj, String str) {
        if (obj == null) {
            throw new NullPointerException(str);
        }
    }

    public static void h(Closeable... closeableArr) {
        for (Closeable closeable : closeableArr) {
            if (closeable != null) {
                try {
                    closeable.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
            }
        }
    }

    public static ContentResolver i() {
        a.n();
        return a.b.getContentResolver();
    }

    public static Uri j(String str, String str2, v vVar) {
        ContentResolver i;
        Uri uri;
        boolean startsWith = str.startsWith(d);
        String str3 = b;
        if (startsWith) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("title", str2);
            contentValues.put("_display_name", str2);
            contentValues.put("mime_type", vVar.d);
            if (str.indexOf(str3) != -1) {
                str = str.substring(str3.length());
            }
            contentValues.put("relative_path", str);
            return i().insert(f.c(), contentValues);
        }
        if (!str.startsWith(e) && !str.startsWith(f)) {
            ContentValues contentValues2 = new ContentValues();
            StringBuilder sb = new StringBuilder();
            if (k(str)) {
                str = "";
            } else {
                String trim = str.trim();
                String str4 = File.separator;
                if (!trim.endsWith(str4)) {
                    str = str.trim() + str4;
                }
            }
            sb.append(str);
            sb.append(str2);
            contentValues2.put("_data", sb.toString());
            contentValues2.put("mime_type", vVar.d);
            return i().insert(MediaStore.Files.getContentUri("external"), contentValues2);
        }
        ContentValues contentValues3 = new ContentValues();
        contentValues3.put("title", str2);
        contentValues3.put("_display_name", str2);
        contentValues3.put("date_added", Long.valueOf(System.currentTimeMillis()));
        contentValues3.put("mime_type", vVar.d);
        contentValues3.put("orientation", (Integer) 0);
        if (str.indexOf(str3) != -1) {
            str = str.substring(str3.length());
        }
        contentValues3.put("relative_path", str);
        String str5 = vVar.e;
        if (!"image".equals(str5)) {
            if ("audio".equals(str5)) {
                i = i();
                uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(str5)) {
                i = i();
                uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            }
            return i.insert(uri, contentValues3);
        }
        i = i();
        uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        return i.insert(uri, contentValues3);
    }

    public static boolean k(CharSequence charSequence) {
        return charSequence == null || charSequence.length() == 0;
    }
}
